package com.yunhe.rentcars.commons.util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.session.SqlSessionManager;

import java.io.InputStream;

/**
 * Created by Administrator on 2017/11/9 0009.
 */
public class MybatisUtils {

    private static SqlSessionFactory sessionFactory;

    static {
        InputStream ras = Thread.currentThread().getContextClassLoader().getResourceAsStream("mybatis-conf.xml");
        sessionFactory = new SqlSessionFactoryBuilder().build(ras);
    }


    public static SqlSession getSession(){
        SqlSessionManager session = SqlSessionManager.newInstance(sessionFactory);
        return session;
    }

   /* public static SqlSession getSession() {
        SqlSession session = sessionFactory.openSession();
        return session;
    }*/

    public static SqlSession getSession(boolean isAutoSubmit) {
        SqlSession session = sessionFactory.openSession(isAutoSubmit);
        return session;
    }

}
